import {url,axios} from '.';

export const getUser = async (user) => {
    let res = await axios({
        method: 'get',
        url: `${url}/users/token`
    });
    return res.data;
}
export const login = async (user) => {
    let res = await axios({
        method: 'post',
        url: `${url}/users/login`,
        data:user
    });
    return res.data;
}
export const listUser = async (current,pageSize) => {
    let res = await axios({
        method: 'get',
        url: `${url}/users`,
        params: {
            current,pageSize
        }
    });
    return res.data;
}
export const listUserRole = async (id) => {
    let res = await axios({
        method: 'get',
        url: `${url}/users/roles/${id}`
    });
    return res.data;
}
export const listUserFunction = async (id) => {
    let res = await axios({
        method: 'get',
        url: `${url}/users/functions/${id}`
    });
    return res.data;
}
export const assignUserRole = async (id,roleIds) => {
    let res = await axios({
        method: 'put',
        url: `${url}/users/assignRole/${id}`,
        data:{
            roleIds
        }
    });
    return res.data;
}
export const assignUserFunction = async (id,functionIds) => {
    let res = await axios({
        method: 'put',
        url: `${url}/users/assignFunction/${id}`,
        data:{
            functionIds
        }
    });
    return res.data;
}

export const addUser = async (user) => {

    let res = await axios({
        method: 'post',
        url: `${url}/users`,
        data:{...user}
    });
    return res.data;
}
export const updateStatus = async (id,status) => {
    let res = await axios({
        method: 'put',
        url: `${url}/users/status/${id}`,
        params:{status}
    });
    return res.data;
}

export const deleteUser = async (id) => {

    let res = await axios({
        method: 'delete',
        url: `${url}/users/${id}`,
    });
    return res.data;
}
